package com.miracle.设计模式.创建型模式.原型模式;


import java.util.ArrayList;
import java.util.List;

public class PrototypePattern {
    public static void main(String[] args) throws CloneNotSupportedException {
        int length  = (int) Math.pow(10, 7);
        List<Integer> list = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            list.add(i, new Integer(i));
        }

        long l1 = System.currentTimeMillis();
        /*for (int i = 0; i < list.size(); i++) {
            list.set(i, new Integer(i+10));
        }*/

        int len = list.size();
        for (int i = 0; i < len; i++) {
            list.set(i, new Integer(i+10));
        }
        long l2 = System.currentTimeMillis();
        System.out.println("T1:"+(l2-l1));


        //----------------------------------------------------------

        for (int i = 0; i < list.size(); i++) {
            list.set(i, new Integer(i-10));
        }
        /*
        int len = list.size();
        for (int i = 0; i < len; i++) {
            list.set(i, new Integer(i-10));
        }*/

        long l3 = System.currentTimeMillis();
        System.out.println("T2:"+(l3-l2));

       /* list = new ArrayList(Collections.singleton(arr));
        for (int i = 0,len = list.size(); i < len; i++) {
            list.set(i, new Integer(i));
        }
        long l3 = System.currentTimeMillis();
        System.out.println("T1:"+(l3-l2));*/
        
        
        //Realizetype realizetype = new Realizetype();
        //Realizetype realizetype2 = (Realizetype)realizetype.clone();
        //System.out.println(realizetype);
        //System.out.println(realizetype2);
    }
}



class Realizetype implements Cloneable{
    Realizetype(){
        System.out.println("具体原型创建成功！");
    }

    public Object clone() throws CloneNotSupportedException {
        System.out.println("具体原型复制成功！");
        return super.clone();
    }
}
